<!-- HTML header for doxygen 1.8.10-->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="generator" content="Doxygen 1.8.10" />
    <title>ZRDDS: simpleinterface/SimpleInterfaceZeroCopyPub.java</title>
    <link href="tabs.css" rel="stylesheet" type="text/css" />
    <script type="text/javascript" src="jquery.js"></script>
    <script type="text/javascript" src="dynsections.js"></script>
    <link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="navtreedata.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<script type="text/javascript">
  $(document).ready(initResizable);
  $(window).load(resizeHeight);
</script>
    <link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/searchdata.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<script type="text/javascript">
  $(document).ready(function() { init_search(); });
</script>
    <link href="doxygen.css" rel="stylesheet" type="text/css" />
    <link href="customdoxygen.css" rel="stylesheet" type="text/css"/>
    <link href="static/css/bootstrap.css" rel="stylesheet" />
    <!-- <link href="static/css/sticky-footer-navbar.css" rel="stylesheet">
    <script type="text/javascript" src="static/js/bootstrap.js"></script> -->
    <script type="text/javascript" src="static/js/doxy-boot.js"></script>
</head>
<body>
    <div id="top">
        <!-- do not remove this div, it is closed by doxygen! -->
        <!-- end header part --><!-- 制作者 Doxygen 1.8.10 -->
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "search",false,'搜索');
</script>
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>首页</span></a></li>
      <li><a href="pages.html"><span>相关页面</span></a></li>
      <li><a href="namespaces.html"><span>包</span></a></li>
      <li><a href="annotated.html"><span>类</span></a></li>
      <li><a href="examples.html"><span>示例</span></a></li>
      <li>
        <div id="MSearchBox" class="MSearchBoxInactive">
        <span class="left">
          <img id="MSearchSelect" src="search/mag_sel.png"
               onmouseover="return searchBox.OnSearchSelectShow()"
               onmouseout="return searchBox.OnSearchSelectHide()"
               alt=""/>
          <input type="text" id="MSearchField" value="搜索" accesskey="S"
               onfocus="searchBox.OnSearchFieldFocus(true)" 
               onblur="searchBox.OnSearchFieldFocus(false)" 
               onkeyup="searchBox.OnSearchFieldChange(event)"/>
          </span><span class="right">
            <a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.png" alt=""/></a>
          </span>
        </div>
      </li>
    </ul>
  </div>
</div><!-- top -->
<div id="side-nav" class="ui-resizable side-nav-resizable">
  <div id="nav-tree">
    <div id="nav-tree-contents">
      <div id="nav-sync" class="sync"></div>
    </div>
  </div>
  <div id="splitbar" style="-moz-user-select:none;" 
       class="ui-resizable-handle">
  </div>
</div>
<script type="text/javascript">
$(document).ready(function(){initNavTree('simpleinterface_2_simple_interface_zero_copy_pub_8java-example.html','');});
</script>
<div id="doc-content">
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>

<div class="header">
  <div class="headertitle">
<div class="title">simpleinterface/SimpleInterfaceZeroCopyPub.java</div>  </div>
</div><!--header-->
<div class="contents">
<p>该程序展示了扩展接口中SimpleInterfaceZeroCopyPub的示例代码。</p>
<div class="fragment"><div class="line"><span class="keyword">package </span>simpleinterface;</div>
<div class="line"></div>
<div class="line"><span class="keyword">import</span> <a class="code" href="namespacecom.html">com</a>.<a class="code" href="namespacecom_1_1zrdds.html">zrdds</a>.<a class="code" href="namespacecom_1_1zrdds_1_1domain.html">domain</a>.<a class="code" href="interfacecom_1_1zrdds_1_1domain_1_1_domain_participant.html">DomainParticipant</a>;</div>
<div class="line"><span class="keyword">import</span> <a class="code" href="namespacecom.html">com</a>.<a class="code" href="namespacecom_1_1zrdds.html">zrdds</a>.<a class="code" href="namespacecom_1_1zrdds_1_1domain.html">domain</a>.<a class="code" href="classcom_1_1zrdds_1_1domain_1_1_domain_participant_factory.html">DomainParticipantFactory</a>;</div>
<div class="line"><span class="keyword">import</span> <a class="code" href="namespacecom.html">com</a>.<a class="code" href="namespacecom_1_1zrdds.html">zrdds</a>.<a class="code" href="namespacecom_1_1zrdds_1_1infrastructure.html">infrastructure</a>.*;</div>
<div class="line"><span class="keyword">import</span> <a class="code" href="namespacecom.html">com</a>.<a class="code" href="namespacecom_1_1zrdds.html">zrdds</a>.<a class="code" href="namespacecom_1_1zrdds_1_1publication.html">publication</a>.<a class="code" href="interfacecom_1_1zrdds_1_1publication_1_1_data_writer.html">DataWriter</a>;</div>
<div class="line"><span class="keyword">import</span> <a class="code" href="namespacecom.html">com</a>.<a class="code" href="namespacecom_1_1zrdds.html">zrdds</a>.<a class="code" href="namespacecom_1_1zrdds_1_1simpleinterface.html">simpleinterface</a>.<a class="code" href="classcom_1_1zrdds_1_1simpleinterface_1_1_d_d_s_i_f.html">DDSIF</a>;</div>
<div class="line"></div>
<div class="line"><span class="keyword">public</span> <span class="keyword">class </span>simpleInterfaceZeroCopyPub</div>
<div class="line">{</div>
<div class="line"></div>
<div class="line">    <span class="keyword">public</span> <span class="keyword">static</span> <span class="keywordtype">void</span> main(String[] args) {</div>
<div class="line">        <span class="comment">// 初始化DDS</span></div>
<div class="line">        DomainParticipantFactory factory = DDSIF.<a name="a0"></a><a class="code" href="classcom_1_1zrdds_1_1simpleinterface_1_1_d_d_s_i_f.html#a087adf3b92e9f3942ae6f40bfc6c1ce1">init</a>(<span class="stringliteral">&quot;ZRDDS_QOS_PROFILES.xml&quot;</span>, <span class="stringliteral">&quot;non_rio&quot;</span>);</div>
<div class="line">        <span class="keywordflow">if</span> (factory == null) {</div>
<div class="line">            System.out.println(<span class="stringliteral">&quot;DDSIF.init failed.&quot;</span>);</div>
<div class="line">            <span class="keywordflow">return</span>;</div>
<div class="line">        }</div>
<div class="line">        <span class="comment">// 创建使用tcp的域参与者</span></div>
<div class="line">        DomainParticipant tcpParticipant = DDSIF.create_dp(100, <span class="stringliteral">&quot;tcp_dp&quot;</span>);</div>
<div class="line">        <span class="keywordflow">if</span> (tcpParticipant == null) {</div>
<div class="line">            System.out.println(<span class="stringliteral">&quot;create tcp dp failed.&quot;</span>);</div>
<div class="line">            <span class="keywordflow">return</span>;</div>
<div class="line">        }</div>
<div class="line">        <span class="comment">// 发布SeaTrack主题,如果需与C/C++中的零拷贝互通，则传入ZeroCopyBytesTypeSupport.get_instance，使用的数据类型还是BytesDataWriter/BytesDataReader/Bytes</span></div>
<div class="line">        DataWriter writer = DDSIF.pub_topic(tcpParticipant, <span class="stringliteral">&quot;SeaTrack&quot;</span>, ZeroCopyBytesTypeSupport.get_instance(), <span class="stringliteral">&quot;zerocopy&quot;</span>, null);</div>
<div class="line">        BytesDataWriter bytesDataWriter = (BytesDataWriter)writer;</div>
<div class="line">        <span class="keywordflow">if</span> (bytesDataWriter == null) {</div>
<div class="line">            System.out.println(<span class="stringliteral">&quot;pub SeaTrack topic failed.&quot;</span>);</div>
<div class="line">            <span class="keywordflow">return</span>;</div>
<div class="line">        }</div>
<div class="line"></div>
<div class="line">        <span class="comment">// 发送数据</span></div>
<div class="line">        <span class="keywordtype">int</span> count = 0;</div>
<div class="line">        <span class="keywordflow">while</span> (count++ &lt; 2000) {</div>
<div class="line">            String content = <span class="stringliteral">&quot;sea track value &quot;</span> + count + <span class="stringliteral">&quot; from java simpleInterfaceZeroCopyPub.&quot;</span>;</div>
<div class="line">            byte[] buffer = content.getBytes();</div>
<div class="line">            System.out.println(<span class="stringliteral">&quot;write sample &quot;</span> + content);</div>
<div class="line">            <span class="comment">// 第一种发送数据方法，直接指定DataWrtier的指针</span></div>
<div class="line">            <span class="comment">//Bytes sample = new Bytes();</span></div>
<div class="line">            <span class="comment">//DDSIF.BytesWrapper(sample, buffer, buffer.length);</span></div>
<div class="line">            <span class="comment">//ReturnCode_t retCode = bytesDataWriter.write(sample, InstanceHandle_t.HANDLE_NIL_NATIVE);</span></div>
<div class="line">            <span class="comment">// 第二种发送数据的方法，指定域与主题名称</span></div>
<div class="line">            ReturnCode_t retCode = DDSIF.BytesWrite(100, <span class="stringliteral">&quot;SeaTrack&quot;</span>, buffer, buffer.length);</div>
<div class="line">            <span class="keywordflow">if</span> (retCode != ReturnCode_t.RETCODE_OK) {</div>
<div class="line">                System.out.println(<span class="stringliteral">&quot;DDSIF::BytesWrite failed.&quot;</span>);</div>
<div class="line">            }</div>
<div class="line">            <span class="keywordflow">try</span> {</div>
<div class="line">                Thread.sleep(1000);</div>
<div class="line">            } <span class="keywordflow">catch</span> (InterruptedException e) {</div>
<div class="line">                e.printStackTrace();</div>
<div class="line">            }</div>
<div class="line">        }</div>
<div class="line">        DDSIF.Finalize();</div>
<div class="line">    }</div>
<div class="line">}</div>
</div><!-- fragment --> </div><!-- contents -->
</div><!-- doc-content -->
<!-- HTML footer for doxygen 1.8.10-->
<!-- start footer part -->
<div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
  <ul>
    <li class="footer">
      <a href="http://www.zrtechnology.com">&copy; Copyright (c) 2018 ZhenRong Technology, Inc. All rights reserved.</a>
    </li>
  </ul>
</div>
</body>
</html>
